<template>
  <div>
    <!--通过state获取共享数据sum-->
    <h1>当前求和为：{{he}}</h1>
    <h3>当前求和放大10倍为：{{bigSum}}</h3>
    <h3>我在{{xuexiao}}学习{{xueke}}</h3>
    <h3 style="color:red">Person组件的总人数是：{{personList.length}}</h3>
    <select v-model.number="n"> <!--.number表示将输入转为数字类型接收-->
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increment(n)">+</button>
    <button @click="decrement(n)">-</button>
    <button @click="incrementOdd(n)">当前求和为奇数再加</button>
    <button @click="incrementWait(n)">等一等再加</button>
  </div>
</template>

<script>
//引入vuex的mapState，mapGetters
import {mapState, mapGetters} from 'vuex'
//引入vuex的mapActions，mapMutations
import {mapActions, mapMutations} from 'vuex'
export default {
    name: 'Count',
    data() {
        return {
            n: 1, //用户选的数字
        }
    },
    computed: {
        ...mapState({
            he: 'sum',
            xuexiao: 'school',
            xueke: 'subject',
            personList: 'personList',
        }),

        ...mapGetters({
            bigSum: 'bigSum',
        })
    },
    methods: {
        ...mapMutations({
            increment: 'JIA',
            decrement: 'JIAN',
        }),

        ...mapActions({
            incrementOdd: 'jiaOdd',
            incrementWait: 'jiaWait',
        })
    }
}
</script>

<style scoped>
    button {
        margin-left: 5px;
        margin-right: 5px;
    }
</style>